package com.whut.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.whut.mapper.PrefixParSystemMapper;
import com.whut.mapper.ProblemDescriptionMapper;
import com.whut.model.ParPrefixSystem;
import com.whut.model.ProblemDescription;
import com.whut.model.UrlProperties;
import com.whut.service.PrefixSystemService;
import com.whut.utils.FileUtil;
import org.apache.poi.ss.usermodel.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

import static org.apache.poi.ss.usermodel.CellType.BLANK;

@Service("prefixSystemService")
public class PrefixSystemServiceImpl implements PrefixSystemService {

    @Resource
    private PrefixParSystemMapper prefixParSystemMapper;
   @Resource
    private ProblemDescriptionMapper problemdescriptionMapper;
    @Resource
    private UrlProperties urlProperties;
    List<String> error_list = null;

    @Override
    public String importSystem(String pathName) {

        try{
            prefixParSystemMapper.deleteAll();
            problemdescriptionMapper.deleteAll();
            error_list = new ArrayList<>();
            System.out.println(pathName);
            find(pathName,0,1);
            System.out.println(error_list.toString());
            return error_list.toString();
        }catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public List<ParPrefixSystem> getFirstLevel() {
        List<ParPrefixSystem> list = prefixParSystemMapper.getFirstLevel(1);
        return list;
    }

    @Override
    public List<ParPrefixSystem> getNextLevel(int preNum) {
        return prefixParSystemMapper.getNextLevel(preNum);
    }

    @Override
    public List<ProblemDescription> getLastLevel(int preNum) {
        List<ProblemDescription> list = problemdescriptionMapper.getLastLevel(preNum);
        return list;
    }

    @Override
    public int getFatherInPrefixSystem(int number) {
        ParPrefixSystem prefixsystem = prefixParSystemMapper.getFather(number);
        return prefixsystem.getPreNum();
    }

    @Override
    public int getFatherInProblemDescription(int number) {
        ProblemDescription problemdescription = problemdescriptionMapper.getFather(number);
        return problemdescription.getPreNum();
    }

    @Override
    public List<ParPrefixSystem> getSameFather(int preNum) {
        return prefixParSystemMapper.getNextLevel(preNum);
    }

    public void find(String pathName,int preIndex,int depth) throws IOException {
        //获取pathName的File对象
        File dirFile = new File(pathName);
        //判断该文件或目录是否存在，不存在时在控制台输出提醒
        if (!dirFile.exists()) {
            System.out.println("do not exit");
            return ;
        }

        //获取此目录下的所有文件名与目录名
        String[] fileList = dirFile.list();

        if(fileList.length == 0){
            return;
        }
        //最后一层深度
        if(depth == 7){
            for(int i = 0;i < fileList.length;i++){
                File file = new File(dirFile.getPath(),fileList[i]);
                if(!file.getName().contains("~$"))
                    readExcel2(file.getAbsolutePath(),preIndex);
            }
            return;
        }else {
            Queue<ParPrefixSystem> queue = new LinkedList<>();
            /*
                用queue保存excel中的记录
             */
            for(int i = 0; i < fileList.length;i++){
                String str = fileList[i];
                File file = new File(dirFile.getPath(),str);
                if(!file.isDirectory() && file.isFile()){
                    if(!file.getName().contains("~$")){   //剔除隐藏文件
                        readExcel1(file.getAbsolutePath(),preIndex,queue);
                    }
                }
            }
            /*
                根据excel的顺序，依次访问文件夹
             */
            while (!queue.isEmpty()){
                ParPrefixSystem p = queue.poll();
                //获得插入的记录的主键，并作为直接子项的前置序号
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                p.setNewCreateTime(formatter.format(date));
                p.setLastEditTime(formatter.format(date));
                prefixParSystemMapper.insert(p);
                int key = p.getNumber();
                String name = p.getParameterName();
                if(name == null){
                    break;
                }
                for(int i = 0;i < fileList.length;i++){
                    String s = fileList[i];
                    File file = new File(dirFile.getPath(),s);
                    if(s.equals(name.trim()) && file.isDirectory() ){
                        //将key作为下一层的前置序号
                        find(file.getCanonicalPath(),key,depth+1);
                        break;
                    }
                }
            }
        }
    }

    /*
        读取中间深度的excel文件内容
     */
    public void readExcel1(String fileName,int preKey,Queue<ParPrefixSystem> queue){
        Workbook table = openExcel(fileName);
        Sheet sheet = table.getSheetAt(0);

        try{

        int rowCount = sheet.getLastRowNum();
        for(int rowIndex = 1;rowIndex <= rowCount;rowIndex++){
            Row row = sheet.getRow(rowIndex);
            /*
                参数名称 列为null，读取文件结束
                1.没有值和样式
                2.有样式没有值
             */
            if(row == null || row.getCell(1,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL) == null || row.getCell(1).equals("") || row.getCell(1).getCellTypeEnum() == BLANK){
                break;
            }
            int columnCount = row.getPhysicalNumberOfCells();
            ParPrefixSystem p = new ParPrefixSystem();
            p.setPreNum(preKey);
            for(int columnIndex = 1;columnIndex < columnCount;columnIndex++){   //列
                Cell cell = row.getCell(columnIndex,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
                if(cell == null)
                    break;
                String temp = null;
                switch (cell.getCellTypeEnum()){
                    case STRING:{
                        temp = cell.getRichStringCellValue().getString().trim();
                        p.setParameterName(temp);
                        break;
                    }
                    case NUMERIC:{
                        double d = cell.getNumericCellValue();
                        if(d-(int)d == 0){  //整数
                            temp = String.valueOf((int)d);
                        }else {
                            temp = new BigDecimal(Double.toString(d)).toString().replaceFirst("00\\d+","");
                        }
                        switch (columnIndex){
                            case 2:{
                                p.setNodeDepth(temp);
                                break;
                            }
                            case 3:{
                                p.setSort(temp);
                                break;
                            }
                            case 4:{
                                p.setPoint(temp);
                                break;
                            }
                            case 5:{
                                float f = Float.parseFloat(temp);
                                temp = (int)(f*100)+"%";
                                p.setWeight(temp);
                                break;
                            }
                        }
                        break;
                    }
                    default:break;
                }
            }
            queue.offer(p);
        }

        }catch (Exception e){
            try{
                table.close();
            }catch (IOException io){
                io.printStackTrace();
            }
            error_list.add("readExcel1"+" "+fileName);
            e.printStackTrace();
        }
    }

    /*
        读取最后深度的excel文件内容
     */
    public void readExcel2(String fileName,int preKey){
        Workbook workbook = openExcel(fileName);
        Sheet sheet = workbook.getSheetAt(0);

        try{

        int rowCount = sheet.getLastRowNum();
        for(int rowIndex = 2;rowIndex <= rowCount;rowIndex++){
            Row row = sheet.getRow(rowIndex);
            if(row == null || row.getCell(1,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL) == null || row.getCell(1).getCellTypeEnum() == BLANK){
                break;
            }
            ProblemDescription problemdescription = new ProblemDescription();
            problemdescription.setPreNum(preKey);
            ArrayList<String> suggestion = new ArrayList<>();
            int colCount = row.getPhysicalNumberOfCells();
            for(int colIndex = 1;colIndex < colCount;colIndex++){
                Cell cell = row.getCell(colIndex,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
                if(cell == null){
                    if(colIndex == 1)   //问题描述不允许为空，否则判为文件读取完成
                        break;
                    continue;       //跳过空单元格
                }
                String string;
                switch (cell.getCellTypeEnum()){
                    case STRING:{
                        string = cell.getRichStringCellValue().getString().trim();
                        if(string.contains("\n")){
                            string = string.replace("\n",";");
                        }
                        switch (colIndex){
                            case 1:{
                                problemdescription.setProblemDescription(string);
                                break;
                            }
                            case 2:{
                                problemdescription.setNormsProvison(string);
                                break;
                            }
                            case 3:{
                                problemdescription.setProblemNum(string);
                                break;
                            }
                            case 4:{
                                problemdescription.setDeductPoint(string);
                                break;
                            }
                            case 5:{
                                problemdescription.setRiskLevel(string);
                                break;
                            }
                            case 6:{
                                problemdescription.setExtraPoint(string);
                                break;
                            }
                            default:{
                                suggestion.add(string);
                            }
                        }
                        break;
                    }
                    case NUMERIC:{      //扣除分数，特征值，附加扣分可能存在各一个数字
                        double d = cell.getNumericCellValue();
                        if(d-(int)d == 0){  //整数
                            string = String.valueOf((int)d);
                        }else {
                            string = new BigDecimal(Double.toString(d)).toString().replaceFirst("00\\d+","");
                        }
                        switch (colIndex){
                            case 4:{
                                problemdescription.setDeductPoint(string);
                                break;
                            }
                            case 5:{
                                problemdescription.setRiskLevel(string);
                                break;
                            }
                            case 6:{
                                problemdescription.setExtraPoint(string);
                                break;
                            }
                        }
                        break;
                    }

                    default:
                        break;
                }
            }
            problemdescription.setSuggestion(JSON.toJSONString(suggestion));
            problemdescriptionMapper.insert(problemdescription);
        }

        }catch (Exception e){
            try{
                workbook.close();
            }catch (IOException io){
                io.printStackTrace();
            }
            error_list.add("readExcel2"+" "+fileName);
            e.printStackTrace();
        }
    }

    private Workbook openExcel(String ExcelName) {
//        System.out.println(ExcelName);
        InputStream inp;
        try {
            inp = new FileInputStream(ExcelName);
        } catch (FileNotFoundException e) {
            // 执行到这里，表示找不到文件
            e.printStackTrace();
            return null;
        }
        // 获得工作簿对象
        Workbook workbook = null;
        try {
			/*// 2003版本的excel，用.xls结尾
			wookbook = new HSSFWorkbook(inp);// 得到工作簿
			if(wookbook == null)
				// 2007版本的excel，用.xlsx结尾
				wookbook = new XSSFWorkbook(inp);// 得到工作簿*/
            workbook = WorkbookFactory.create(inp);
        } catch (Exception ex) {
            try {
                workbook.close();
            }catch (IOException io){
//                System.out.println(ExcelName);
                error_list.add("openExcel" + " "+ExcelName);
                io.printStackTrace();
            }
            ex.printStackTrace();
			/*try {
				// 2007版本的excel，用.xlsx结尾
				wookbook = new XSSFWorkbook(inp);// 得到工作簿
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}*/

        }
        return workbook;
    }

    @Override
    public String addPrefixSystem(ParPrefixSystem prefixsystem) {
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());
        prefixsystem.setNewCreateTime(formatter.format(date));
        prefixsystem.setLastEditTime(formatter.format(date));
        try{
            prefixParSystemMapper.insert(prefixsystem);
        }catch (Exception e){
            e.printStackTrace();
            return "error";
        }
        return "success";
    }

    @Override
    public String addProblemdescription(ProblemDescription problemdescription) {
        try {
            problemdescriptionMapper.insert(problemdescription);
        }catch (Exception e){
            e.printStackTrace();
            return "error";
        }
        return "success";
    }

    @Override
    public String delMidOne(int number) {
        ParPrefixSystem p = prefixParSystemMapper.selectByPrimaryKey(number);
        if(p == null){
            return "success";
        }else {
            try{
                prefixParSystemMapper.deleteByPrimaryKey(number);
                return "success";
            }catch (Exception e){
                e.printStackTrace();
                return "error";
            }
        }
    }

    @Override
    public String delLastOne(int number) {
        ProblemDescription p = problemdescriptionMapper.selectByPrimaryKey(number);
        if(p == null){
            return "success";
        }else {
            try{
                problemdescriptionMapper.deleteByPrimaryKey(number);
                return "success";
            }catch (Exception e){
                e.printStackTrace();
                return "error";
            }
        }
    }

    @Override
    public String updateMid(ParPrefixSystem prefixsystem) {
        ParPrefixSystem p = prefixParSystemMapper.selectByPrimaryKey(prefixsystem.getNumber());
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());
        prefixsystem.setLastEditTime(formatter.format(date));
        if(p == null){
            return "success";
        }else {
            try{
                prefixParSystemMapper.updateByPrimaryKeySelective(prefixsystem);
                return "success";
            }catch (Exception e){
                e.printStackTrace();
                return "error";
            }
        }
    }

    @Override
    public String updateLast(ProblemDescription problemdescription) {
        ProblemDescription p = problemdescriptionMapper.selectByPrimaryKey(problemdescription.getNumber());
        if(p == null){
            return "success";
        }else {
            try{
                problemdescriptionMapper.updateByPrimaryKey(problemdescription);
                return "success";
            }catch (Exception e){
                e.printStackTrace();
                return "error";
            }
        }
    }

    @Override
    public String exportExcel() {
        String path = FileUtil.getServerFolderPath();
        File file = new File(path,"temp//安全检查");
        if(!file.exists()){
            file.mkdirs();
        }
        exportExcelDes(0,1,file.getAbsolutePath());
        FileOutputStream fos1;
        Date date = new Date();
        String time = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
        String exportPath = urlProperties.getAddress()+"//temp//" + time + ".zip";
        try{
            fos1 = new FileOutputStream(new File(path,"temp//"+time+".zip"));
        }catch (IOException io){
            io.printStackTrace();
            return "error";
        }
        FileUtil.toZip(file.getAbsolutePath(), fos1,true);
        return exportPath;
    }

    @Override
    public String addAdvice(int number,String advice) {
        ProblemDescription p = problemdescriptionMapper.selectByPrimaryKey(number);
        if(p == null){
            return "success";
        }else {
            try{
                ProblemDescription temp = new ProblemDescription();
                temp.setNumber(number);
                temp.setSuggestion(advice);
                problemdescriptionMapper.updateByPrimaryKeySelective(temp);
                return "success";
            }catch (Exception e){
                e.printStackTrace();
                return "error";
            }
        }
    }


    public void exportExcelDes(int preNum,int depth,String path){
        Map<String,String> headMap1 = new LinkedHashMap<String,String>();	//头标题
        headMap1.put("index","编号");
        headMap1.put("parameterName","参数名称");
        headMap1.put("nodeDepth","节点深度");
        headMap1.put("sort","排序");
        headMap1.put("point","分数");
        headMap1.put("weight","权重");

        Map<String,String> headMap2 = new LinkedHashMap<String,String>();	//头标题
        headMap2.put("index","编号");
        headMap2.put("problemDescription","问题描述");
        headMap2.put("normsProvison","规范与条款");
        headMap2.put("problemNum","问题数量（性质）");
        headMap2.put("deductPoint","扣除分数");
        headMap2.put("riskLevel","特征值");
        headMap2.put("extraPoint","附加扣分");
        headMap2.put("suggestion","建议措施");
        JSONArray ja = new JSONArray();         //用于写入excel文件
        Queue<ParPrefixSystem> queue = new LinkedList<>();
        OutputStream outXls = null;
        try {
            outXls = new FileOutputStream(path+"//aaa.xls");
        }catch (FileNotFoundException fnfe){
            fnfe.printStackTrace();
        }
        /**
         *  生成Excel
         *@date: 2019/6/5 14:29
        */
        if(depth < 7){
            List<ParPrefixSystem> list = prefixParSystemMapper.getNextLevel(preNum);
            for(int i = 0;i < list.size();i++) {
                ja.add(list.get(i));
                queue.offer(list.get(i));
            }
            FileUtil.exportMidExcel(headMap1,ja,outXls);
            try {
                outXls.close();
            }catch (IOException io){
                io.printStackTrace();
            }
        }else {
            List<ProblemDescription> list = problemdescriptionMapper.getLastLevel(preNum);
            for(int i = 0;i < list.size();i++) {
                ja.add(list.get(i));
            }
            FileUtil.exportLastExcel(headMap2,ja,outXls);
            try {
                outXls.close();
            }catch (IOException io){
                io.printStackTrace();
            }
        }

        /**
         *  创建文件夹
         *  递归
         *@date: 2019/6/5 14:30
        */
        while (!queue.isEmpty()){
            ParPrefixSystem p = queue.poll();
            String fileDirName = p.getParameterName();
            File file = new File(path,fileDirName);
            if(!file.exists()){
                file.mkdirs();
            }
            exportExcelDes(p.getNumber(),depth+1,file.getAbsolutePath());
        }



    }


    @Override
        public String discMidOne(int number) {
            try{
                ParPrefixSystem prefixsystem=new ParPrefixSystem();
                prefixsystem.setNumber(number);
                SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
                Date date = new Date(System.currentTimeMillis());
                prefixsystem.setLastEditTime(formatter.format(date));
                if(prefixParSystemMapper.selectByPrimaryKey(number).getIsDeprecated().equals("N")){
                    prefixsystem.setIsDeprecated("Y");
                    prefixParSystemMapper.updateByPrimaryKeySelective(prefixsystem);}
                else {
                    prefixsystem.setIsDeprecated("N");
                    prefixParSystemMapper.updateByPrimaryKeySelective(prefixsystem);}

                return "success";
            }catch (Exception e){
                e.printStackTrace();
                return "error";
            }

        }

        @Override
        public String discLastOne(int number) {
            try{
                ProblemDescription problemdescription=new ProblemDescription();
                problemdescription.setNumber(number);
                if(problemdescriptionMapper.selectByPrimaryKey(number).getIsDeprecated().equals("Y")){
                    problemdescription.setIsDeprecated("N");
                    problemdescriptionMapper.updateByPrimaryKeySelective(problemdescription);}
                else{
                    problemdescription.setIsDeprecated("Y");
                    problemdescriptionMapper.updateByPrimaryKeySelective(problemdescription);}
                return "success";
            }catch (Exception e){
                e.printStackTrace();
                return "error";
            }
    }
    //
    @Override
    public Object getAllSystemInfo() {
        List<Object> list = new ArrayList<Object>();
        List<Object> pNname1InfoList = prefixParSystemMapper.getNumberForJudge("1", 0);
        String pName1Info = JSON.toJSONString(pNname1InfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
        JSONArray pNname1InfoArray = JSONArray.parseArray(pName1Info);
        for (int i = 0; i < pNname1InfoArray.size(); i++) {
            List<Object> listName1 = new ArrayList<Object>();
            Map<String, Object> name1Map = new HashMap<String, Object>();
            int firstId = pNname1InfoArray.getIntValue(i);
            String pName1 = prefixParSystemMapper.getName4ByName4Id(firstId);
            List<Object> secondIdInfoList = prefixParSystemMapper.getNumberForJudge("2", firstId);
            String secondIdInfo = JSON.toJSONString(secondIdInfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
            JSONArray secondIdInfoArray = JSONArray.parseArray(secondIdInfo);
            for (int j = 0; j < secondIdInfoArray.size(); j++) {
                List<Object> listName2 = new ArrayList<Object>();
                Map<String, Object> name2Map = new HashMap<String, Object>();
                int secondId = secondIdInfoArray.getIntValue(j);
                List<Object> thirdIdInfoList = prefixParSystemMapper.getNumberForJudge("3", secondId);
                System.out.println("我没有办法，为了去除重复标记");
                String thirdIdInfo = JSON.toJSONString(thirdIdInfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                JSONArray thirdIdInfoArray = JSONArray.parseArray(thirdIdInfo);
                for (int k = 0; k < thirdIdInfoArray.size(); k++) {
                    List<Object> listName3 = new ArrayList<Object>();
                    Map<String, Object> name3Map = new HashMap<String, Object>();
                    System.out.println("一层嵌套一层");
                    int thirdId = thirdIdInfoArray.getIntValue(k);
                    List<Object> fourthIdInfoList = prefixParSystemMapper.getNumberForJudge("4", thirdId);
                    String fourthIdInfo = JSON.toJSONString(fourthIdInfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                    JSONArray fourthIdInfoArray = JSONArray.parseArray(fourthIdInfo);
                    for (int l = 0; l < fourthIdInfoArray.size(); l++) {
                        System.out.println("唉");
                        List<Object> listName4 = new ArrayList<Object>();
                        Map<String, Object> name4Map = new HashMap<String, Object>();
                        int fourthId = fourthIdInfoArray.getIntValue(l);
                        List<Object> fifthIdInfoList = prefixParSystemMapper.getNumberForJudge("5", fourthId);
                        String fifthIdInfo = JSON.toJSONString(fifthIdInfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                        JSONArray fifthIdInfoArray = JSONArray.parseArray(fifthIdInfo);
                        for(int m=0;m<fifthIdInfoArray.size();m++)
                        {
                            System.out.println("唉");
                            List<Object> listName5 = new ArrayList<Object>();
                            Map<String, Object> name5Map = new HashMap<String, Object>();
                            int fifthId = fifthIdInfoArray.getIntValue(m);
                            List<Object> sixthIdInfoList = prefixParSystemMapper.getNumberForJudge("6", fifthId);
                            String sixthIdInfo = JSON.toJSONString(sixthIdInfoList, SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect);
                            JSONArray sixthIdInfoArray = JSONArray.parseArray(sixthIdInfo);
                            for(int n=0;n<sixthIdInfoArray.size();n++)
                            {
                                Map<String, Object> name6Map = new HashMap<String, Object>();
                                name6Map.put("value", sixthIdInfoArray.getIntValue(n));
                                name6Map.put("label", prefixParSystemMapper.getName4ByName4Id(sixthIdInfoArray.getIntValue(n)));
                                listName5.add(name6Map);
                            }
                            String pName5 = prefixParSystemMapper.getName4ByName4Id(fifthId);
                            name5Map.put("value", fifthId);
                            name5Map.put("label", pName5);
                            name5Map.put("children",listName5);
                            listName4.add(name5Map);
                        }
                        String pName4 = prefixParSystemMapper.getName4ByName4Id(fourthId);
                        name4Map.put("value", fourthId);
                        name4Map.put("label", pName4);
                        name4Map.put("children",listName4);
                        listName3.add(name4Map);
                    }
                    String pName3 = prefixParSystemMapper.getName4ByName4Id(thirdId);
                    name3Map.put("value", thirdId);
                    name3Map.put("label", pName3);
                    name3Map.put("children", listName3);
                    listName2.add(name3Map);
                }
                String pName2 = prefixParSystemMapper.getName4ByName4Id(secondId);
                name2Map.put("value", secondId);
                name2Map.put("label", pName2);
                name2Map.put("children", listName2);
                System.out.println("我也很难受");
                listName1.add(name2Map);
            }
            name1Map.put("value", firstId);
            name1Map.put("label", pName1);
            name1Map.put("children", listName1);
            list.add(name1Map);
        }
        return list;
    }

    @Override
    public Object getSomeSystemInfoByNodeDepth(Integer nodeDepth) {
        List<Object> systemList=prefixParSystemMapper.getItemOnlyByDepth(nodeDepth);
        return systemList;
    }


    @Override
    public Object getProblemDescriptionById(String system) {
        JSONArray jsonArray=JSONArray.parseArray(system);
        List<ProblemDescription> list=new ArrayList<>();
        if(jsonArray.size()==6)
        {
            list=problemdescriptionMapper.getPDBySixthNum(jsonArray.getIntValue(5));
        }
        return list;
    }
}
